package net.grapsus.arduino;

import java.awt.*;
import java.awt.image.*;
import java.util.*;
import javax.imageio.*;

public class ArduinoCanvas extends javax.swing.JPanel {
	public ArduinoCanvas()
	{
		super();
		this.setOpaque(true); // we will paint all the exposed area
		try {
			bg = ImageIO.read(this.getClass().getResource(bgFileName));
		} catch(Exception e) {
			System.err.println("Image could not be read!");
			System.exit(1);
		}
		//this.repaint();
	}
	
	public boolean isOptimizedDrawingEnabled()
	{
		return true; // children won't overlap
	}

	protected void paintComponent(Graphics g)
	{
		int w = bg.getWidth();
		int h = bg.getHeight();
		int W = this.getWidth();
		int H = this.getHeight();
		g.drawImage(bg, 0, 0, W, H, 0, 0, w, h, Color.black, null);
	}

	private String bgFileName = "/pics/lilypad.jpg";
	private BufferedImage bg;
}
